<template>
<div>

  <el-table
    :data="list.slice((currentPage - 1) * pagesize, currentPage * pagesize)"
    style="width: 1100px"
  >
    <el-table-column prop="name" label="资源名" width="300" />
    <el-table-column prop="transferSize" label="资源大小" width="90" />
    <el-table-column prop="initiatorType" label="资源种类" width="90" />
    <el-table-column prop="startTime" label="startTime" width="110" />
    <el-table-column prop="responseEnd" label="responseEnd" width="120" />
    <el-table-column prop="dnsLookUp" label="dnsLookUp" width="110" />
    <el-table-column prop="initialConnect" label="initialConnect" width="150" />
    <el-table-column prop="ssl" label="ssl" width="70" />
    <el-table-column prop="request" label="request" width="90" />
    <el-table-column prop="ttfb" label="ttfb" width="70" />
    <el-table-column
      prop="contentDownload"
      label="contentDownload"
      width="180"
    />
  </el-table>
    <!-- @size-change="handleSizeChange" -->

  <el-pagination
    layout="total,prev,pager,next,jumper"
    :total="list.length"
    @current-change="handleCurrentChange"
    :current-page="currentPage"
  />
</div>
</template>

<script setup>
import {reactive, ref} from "vue"
import { onMounted } from "vue-demi";
import XHR from "../utils/request.js";
import { dataStore } from '@/store/piniastore-data.js';
const dStore = dataStore();
let requestID=dStore.requestID
const currentPage = ref(1); //默认页码为1
const pagesize = ref(10); //默认一页显示10条

const list = reactive([])
onMounted(() => {
  XHR.normalPost("api/data/resource", requestID).then(({ data: { data } }) => {
    console.log(data);
    list.push(...data)
    for (let i = 0; i < data.length; i++) {
      const el = data[i];
      el.contentDownload = Math.round(el.contentDownload * 100) / 100;
      el.request = Math.round(el.request * 100) / 100;
      el.responseEnd = Math.round(el.responseEnd * 100) / 100;
      el.ssl = Math.round(el.ssl * 100) / 100;
      el.startTime = Math.round(el.startTime * 100) / 100;
      el.transferSize = Math.round(el.transferSize * 100) / 100;
      el.ttfb = Math.round(el.ttfb * 100) / 100;
      el.dnsLookUp = Math.round(el.dnsLookUp * 100) / 100;
      el.initialConnect = Math.round(el.initialConnect * 100) / 100;
    }
  });
});
// function handleSizeChange(size) {
//   //一页显示多少条
//   pagesize = size;
// }

function handleCurrentChange(index) {
  //页码更改方法
  currentPage.value = index;
}
</script>

<style>
</style>